
/**
 *
 * @author djk1076
 */
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;

public class AntGUI /*extends JPanel */ {//gui

    private static final int GUI_WIDTH = World.WIDTH;
    private static final int GUI_HEIGHT = World.HEIGHT;
    private static final int GUI_SCALE = 4;
    private World world;
    private int NUM_A_ANTS;
    private int NUM_B_ANTS;
    private JLabel population = new JLabel();
    private JLabel resources = new JLabel();
    private java.util.List<JLabel> antInfoList = new ArrayList();
    private JPanel antInfo;
    private boolean gui;
    private Individual ind;

    public AntGUI(boolean gui, Individual ind) {
        this.ind = ind;
        world = new World(ind);
        world.scatterResources(10, 25);
        this.gui = gui;
        if (gui) {
            antInfo = new JPanel(new GridLayout(0, 1));
            antInfo.add(new JLabel("ants"));
        }
        NUM_A_ANTS = ind.getNum_A_Ants();
        for (int i = 0; i < NUM_A_ANTS; i++) {
            addAnt_A();
        }


        NUM_B_ANTS = ind.getNum_B_Ants();
        for (int i = 0; i < NUM_B_ANTS; i++) {
            addAnt_B();
        }



        world.start();

        /*  if (gui) {
        this.setLayout(new BorderLayout());
        JPanel info = new JPanel(new GridLayout());

        info.add(population);
        info.add(resources);
        this.add(info, BorderLayout.SOUTH);



        this.add(antInfo, BorderLayout.EAST);

        this.addMouseListener(new MouseAdapter() {

        public void mouseReleased(MouseEvent arg0) {
        if (arg0.getButton() == MouseEvent.BUTTON1) {
        world.getWorld()[arg0.getX() / GUI_SCALE][arg0.getY() / GUI_SCALE][world.RESOURCE_A_INDEX] += 30;
        } else {
        world.getWorld()[arg0.getX() / GUI_SCALE][arg0.getY() / GUI_SCALE][world.RESOURCE_B_INDEX] += 30;
        }
        }
        });

        }*///gui
    }

    public void addAnt_A() {
        world.add(new Ant(ind, world.getColonyX(), world.getColonyY(), 'a'));
        /* if (gui) {
        JLabel label = new JLabel();
        antInfoList.add(label);
        antInfo.add(label);
        }*///gui
    }

    public void addAnt_B() {
        world.add(new Ant(ind, world.getColonyX(), world.getColonyY(), 'b'));
        /*     if (gui) {
        JLabel label = new JLabel();
        antInfoList.add(label);
        antInfo.add(label);
        }*/ //gui
    }

    /* public static void main(String[] args) {
    AntGUI gui = new AntGUI(true, null);
    JFrame frame = new JFrame();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(GUI_WIDTH * GUI_SCALE, GUI_HEIGHT * GUI_SCALE + 100);
    frame.setVisible(true);
    frame.getContentPane().add(gui, BorderLayout.CENTER);
    }

    public void paintComponent(Graphics g) {
    population.setText("population: " + world.getPopulation());
    resources.setText("resources gathered: A:" + world.getCurrent_A() + "/" + world.getGathered_A() + ":B" + world.getCurrent_B() + "/" + world.getGathered_B() + "/" + world.getTotal());
    java.util.List<Ant> ants = world.getAnts();
    for (int i = 0; i < ants.size() && i < antInfoList.size(); i++) {
    antInfoList.get(i).setText(ants.get(i).toString());
    }
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, GUI_WIDTH * GUI_SCALE, GUI_HEIGHT * GUI_SCALE);
    double[][][] worldArray = world.getWorld();//[x][y][cost,pheremone,resource]

    for (int r = 0; r < GUI_HEIGHT; r++) {
    for (int c = 0; c < GUI_WIDTH; c++) {
    if (worldArray[c][r][world.RESOURCE_A_INDEX] > 0) {
    g.setColor(new Color(0, 0, (int) (worldArray[c][r][world.RESOURCE_A_INDEX] * 10) % 255));
    g.fillRect(c * GUI_SCALE, r * GUI_SCALE, GUI_SCALE, GUI_SCALE);
    } else if (worldArray[c][r][world.PHEREMONE_A_INDEX] > 0) {
    g.setColor(new Color(((int) (worldArray[c][r][world.PHEREMONE_A_INDEX] * 100) % 255), 0, 0));
    g.fillRect(c * GUI_SCALE, r * GUI_SCALE, GUI_SCALE, GUI_SCALE);
    }



    if (worldArray[c][r][world.RESOURCE_B_INDEX] > 0) {
    g.setColor(new Color(0, 255, (int) (worldArray[c][r][world.RESOURCE_B_INDEX] * 10) % 255));
    g.fillRect(c * GUI_SCALE, r * GUI_SCALE, GUI_SCALE, GUI_SCALE);
    } else if (worldArray[c][r][world.PHEREMONE_B_INDEX] > 0) {
    g.setColor(new Color(((int) (worldArray[c][r][world.PHEREMONE_B_INDEX] * 100) % 255), 255, 0));
    g.fillRect(c * GUI_SCALE, r * GUI_SCALE, GUI_SCALE, GUI_SCALE);
    }
    }
    }



    g.setColor(Color.BLACK);
    for (Ant ant : world.getAnts()) {
    g.fillRect(ant.getX() * GUI_SCALE, ant.getY() * GUI_SCALE, GUI_SCALE, GUI_SCALE);
    }

    g.setColor(Color.GREEN);
    g.fillRect(world.getColonyX() * GUI_SCALE, world.getColonyY() * GUI_SCALE, GUI_SCALE * 4, GUI_SCALE * 4);
    }*///gui
}

